#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn=100000, maxm=100000, sumj=1000000, mods=998244353;

class Graph {
    public:
        bool vis[maxm+2];
        int n, m, ind[maxm+2], to[maxm+sumj+1], link[maxm+sumj+1], deg[maxm+2];
        ll add[maxm+2][2], mul[maxm+2];

        void init() {for (int i=1; i<=maxm+2; i++) mul[i]=1;}

        void addSide(int u, int v) {
            m++;
            to[m] = v;
            deg[v]++;
            link[m] = ind[u];
            ind[u] = m;
        }

        ll initMul(int o) {
            if (!vis[o]) {
                vis[o] = true;
                for (int i=ind[o]; i; i=link[i]) {
                    mul[o] = mul[o]*initMul(to[i])%mods;
                }
            }
            return mul[o];
        }

        void solve(int s, ll ans[]) {
            static int que[maxm+2];
            static ll f[maxm+2];
            int h=0, t=0;
            f[s] = 1;
            for (int i=1; i<=n; i++) {
                if (!deg[i]) que[++t] = i;
            }

            for (; h<t; ) {
                int o=que[++h];
                ll tot=f[o];
                ans[add[o][0]] = (ans[add[o][0]]+f[o]*add[o][1]%mods)%mods;
                for (int i=ind[o]; i; i=link[i]) {
                    f[to[i]] = (f[to[i]]+tot)%mods;
                    tot = (tot*mul[to[i]])%mods;
                    if (--deg[to[i]]==0) que[++t] = to[i];
                }
            }
        }
};

int main() {
    freopen("call.in", "r", stdin);
    freopen("call.out", "w", stdout);

    static Graph g;
    static int a[maxn+1];
    int n, m, q;
    scanf("%d", &n);
    for (int i=1; i<=n; i++) scanf("%d", a+i);
    scanf("%d", &m);
    g.init();
    for (int i=1; i<=m; i++) {
        int opt;
        scanf("%d", &opt);
        if (opt==1) scanf("%lld %lld", g.add[i], g.add[i]+1);
        else if (opt==2) scanf("%lld", g.mul+i);
        else {
            int c, t;
            scanf("%d", &c);
            for (int j=1; j<=c; j++) {
                scanf("%d", &t);
                g.addSide(i, t);
            }
        }
    }
    g.n = m+1;
    scanf("%d", &q);
    for (int i=1; i<=q; i++) {
        int t;
        scanf("%d", &t);
        g.addSide(m+1, t);
    }

    static ll ans[maxn+1];
    g.initMul(m+1);
    g.solve(m+1, ans);
    for (int i=1; i<=n; i++) {
        printf("%lld ", (ans[i]+g.mul[m+1]*a[i]%mods)%mods);
    }
    printf("\n");

    fclose(stdin);
    fclose(stdout);
    return 0;
}
